package com.ruoyi.tasks.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.tasks.dto.HouseholdTasksDto;
import com.ruoyi.tasks.dto.TaskDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.tasks.domain.HouseholdTasks;
import com.ruoyi.tasks.service.IHouseholdTasksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 住户核酸任务CRUDController
 * 
 * @author ruoyi
 * @date 2022-10-05
 */
@RestController
@RequestMapping("/household")
public class HouseholdTasksController extends BaseController
{
    @Autowired
    private IHouseholdTasksService householdTasksService;

    @PostMapping("/getUrl")
    public AjaxResult getUrl(@RequestBody TaskDto dto)
    {
        return AjaxResult.success(householdTasksService.getUrl(dto));
    }

    @PostMapping("/Finish")
    public AjaxResult getFinish(@RequestBody TaskDto dto)
    {
        return toAjax(householdTasksService.updateFinish(dto));
    }

    /**
     * 查询住户核酸任务CRUD列表
     */
    @RequiresPermissions("tasks:household:list")
    @GetMapping("/list")
    public TableDataInfo list(HouseholdTasks householdTasks)
    {
        startPage();
        List<HouseholdTasks> list = householdTasksService.selectHouseholdTasksList(householdTasks);
        return getDataTable(list);
    }

    /**
     * 导出住户核酸任务CRUD列表
     */
    @RequiresPermissions("tasks:household:export")
    @Log(title = "住户核酸任务CRUD", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseholdTasks householdTasks)
    {
        List<HouseholdTasks> list = householdTasksService.selectHouseholdTasksList(householdTasks);
        ExcelUtil<HouseholdTasks> util = new ExcelUtil<HouseholdTasks>(HouseholdTasks.class);
        util.exportExcel(response, list, "住户核酸任务CRUD数据");
    }

    /**
     * 获取住户核酸任务CRUD详细信息
     */
    @RequiresPermissions("tasks:household:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(householdTasksService.selectHouseholdTasksById(id));
    }

    /**
     * 新增住户核酸任务CRUD
     */
    @RequiresPermissions("tasks:household:add")
    @Log(title = "住户核酸任务CRUD", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseholdTasksDto dto)
    {
        return toAjax(householdTasksService.insertHouseholdTasks(dto));
    }

    /**
     * 修改住户核酸任务CRUD
     */
    @RequiresPermissions("tasks:household:edit")
    @Log(title = "住户核酸任务CRUD", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseholdTasks householdTasks)
    {
        return toAjax(householdTasksService.updateHouseholdTasks(householdTasks));
    }

    /**
     * 删除住户核酸任务CRUD
     */
    @RequiresPermissions("tasks:household:remove")
    @Log(title = "住户核酸任务CRUD", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(householdTasksService.deleteHouseholdTasksByIds(ids));
    }
}
